﻿using Cysharp.Threading.Tasks;
using System.Collections;
using System.Threading;
using UnityEngine;
using UnityEngine.UI;

public static partial class Extensions
{
    /// <summary>
    /// 加载 sprite 资源。
    /// 需要资源存在于 Addressable/Sprites/ 路径下
    /// </summary>
    public static async UniTask LoadSpriteAsync(this Image image, string spriteName, string fallback = null, bool setNativeSize = false, CancellationToken cancellationToken = default)
    {
        await Tools.LoadSpriteAsync(image, spriteName, fallback, setNativeSize, cancellationToken);
    }

    /// <summary>
    /// 加载 sprite 资源。
    /// 需要资源存在于 Addressable/Sprites/ 路径下
    /// </summary>
    public static void LoadSprite(this Image image, string spriteName, string fallback = null, bool setNativeSize = false, CancellationToken cancellationToken = default)
    {
        Tools.LoadSpriteAsync(image, spriteName, fallback, setNativeSize, cancellationToken).Forget();
    }


    /// <summary>
    /// 加载 sprite 资源。
    /// 需要资源存在于 Addressable/Sprites/ 路径下
    /// </summary>
    public static async UniTask LoadSpriteAsync(this SpriteRenderer spriteRenderer, string spriteName, string fallback = null, CancellationToken cancellationToken = default)
    {
        await Tools.LoadSpriteAsync(spriteRenderer, spriteName, fallback, cancellationToken);
    }


    /// <summary>
    /// 加载 sprite 资源。
    /// 需要资源存在于 Addressable/Sprites/ 路径下
    /// </summary>
    public static void LoadSprite(this SpriteRenderer spriteRenderer, string spriteName, string fallback = null, CancellationToken cancellationToken = default)
    {
        Tools.LoadSpriteAsync(spriteRenderer, spriteName, fallback, cancellationToken).Forget();
    }
}
